/**
 * 作者：yujinjin9@126.com
 * 时间：2017-01-19
 * app临时数据管理
 */
import storage from '@/utils/localstorage'
import cityData from 'static/js/city-data'
export default {
  state: {
    navbarTitle: '首页', // app的导航页标题
    isShowHead: false, // 是否显示app 的导航栏
    isShowFoot: true, // 是否显示foot栏
    isShowBack: true, // 是否显示返回按钮
    isShowClear: false, // 是否显示垃圾桶按钮
    isShowSousuo: false, // 是否显示搜索按钮
    isConnectionHub: false, // 是否连接hubs
    adHas: false,
    hasWindow: false,
    locationInfo: {},
    picturesList: '',
    globalConfig: storage.getLocalstorage('globalConfig'),
    imgUrl: process.env.PATH_INDEX_PIC,
    headerContentType: 'application/json;charset=UTF-8',
    cachePrevPageStatuts: false,
    pagingMsg: {},
    pigingobj: {},
    filterScrollY: 0,
    cityData3: cityData,
    wxShow: true
    // carTypes: [
    //   '新能源',
    //   '微面',
    //   '轿车',
    //   'SUV',
    //   '轻客',
    //   'MPV',
    //   '跑车',
    //   '皮卡',
    //   '微卡'
    // ],
    // sourceCountrys: [
    //   '自主品牌',
    //   '合资品牌',
    //   '中规进口',
    //   '平行进口'
    // ]
  },
  getters: {
    hasWindow (state) {
      return state.hasWindow
    },
  },
  actions: {
    updateHasWindow({
      commit
    }, data) {
      commit("updateHasWindow", data);
    },
    updateWxShow({
      commit
    }, data) {
      commit("updateWxShow", data);
    },
    updateLocationInfo({
      commit
    }, locationInfo) {
      commit("updateLocationInfo", locationInfo);
    },
    updateNavbarTitle({
      commit
    }, navbarTitle) {
      commit("updateNavbarTitle", navbarTitle);
    },
    updateNavbarStatus({
      commit
    }, navbarStatusObject) {
      commit("updateNavbarStatus", navbarStatusObject);
    },
    updateConnectionHubStatus({
      commit
    }, isConnectionHub) {
      commit("updateConnectionHubStatus", isConnectionHub);
    },
    updateHeaderContentTypeStatus({commit}, headerContentTypeStatus) {
      commit("updateHeaderContentTypeStatus", headerContentTypeStatus);
    },
    updateCachePrevPageStatuts({commit}, status) {
      commit("updateCachePrevPageStatuts", status);
    },
    updatePigingobj({commit}, data) {
      commit("updatePigingobj", data);
    },
    updatePagingMsg({commit}, data) {
      commit("updatePagingMsg", data);
    },
    updateFilterScrollY({commit}, data) {
      commit("updateFilterScrollY", data);
    }
  },
  mutations: {
    // 重置appData页面保留数据
    resetAppData(state) {
      state = {
        navbarTitle: '首页', // app的导航页标题
        isShowHead: false, // 是否显示app 的导航栏
        isShowFoot: true, // 是否显示foot栏
        isShowBack: true, // 是否显示返回按钮
        isShowClear: false, // 是否显示垃圾桶按钮
        isShowSousuo: false, // 是否显示搜索按钮
        isConnectionHub: false, // 是否连接hubs
        adHas: false,
        hasWindow: false,
        locationInfo: {},
        picturesList: '',
        globalConfig: storage.getLocalstorage('globalConfig'),
        imgUrl: process.env.PATH_INDEX_PIC,
        headerContentType: 'application/json;charset=UTF-8',
        cachePrevPageStatuts: false,
        pagingMsg: {},
        pigingobj: {},
        filterScrollY: 0,
        cityData3: cityData
      }
    },
    updateHasWindow(state, data) {
      state.hasWindow = data
    },
    AD_HAS(state, adHas) {
      state.adHas = adHas
    },
    // 保存用户id 以便调用此数据
    PicturesList(state, picturesList) {
      state.picturesList = picturesList
      // //console.log(state.userId)
    },
    updateCachePrevPageStatuts(state, status) {
      state.cachePrevPageStatuts = status;
    },
    updateLocationInfo(state, locationInfo) {
      state.locationInfo = locationInfo;
    },
    updateNavbarTitle(state, navbarTitle) {
      state.navbarTitle = navbarTitle;
    },
    updateNavbarStatus(state, {
      isShowHead = true,
      isShowFoot = true,
      isShowBack = true,
      isShowClear = false,
      isShowSousuo = false
    } = {}) {
      if (state.isShowHead != isShowHead) {
        state.isShowHead = isShowHead;
      }
      if (state.isShowFoot != isShowFoot) {
        state.isShowFoot = isShowFoot;
      }
      if (state.isShowBack != isShowBack) {
        state.isShowBack = isShowBack;
      }
      if (state.isShowClear != isShowClear) {
        state.isShowClear = isShowClear;
      }
      if (state.isShowSousuo != isShowSousuo) {
        state.isShowSousuo = isShowSousuo;
      }
    },
    updateConnectionHubStatus(state, isConnectionHub) {
      state.isConnectionHub = isConnectionHub;
    },
    updateHeaderContentTypeStatus(state, headerContentType) {
      state.headerContentType = headerContentType
    },
    updatePigingobj(state, pigingobj) {
      state.pigingobj = pigingobj
    },
    updatePagingMsg(state, pagingMsg) {
      state.pagingMsg = pagingMsg
    },
    updateFilterScrollY(state, filterScrollY) {
      state.filterScrollY = filterScrollY
    },
    updateWxShow(state, data){
      state.wxShow = data
    }
  }
}
